<?php

/**
 * Created by PhpStorm.
 * User: lihao
 * Date: 2017/9/6
 * Time: 下午12:50
 */
class Api extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('Photo_model');
    }

    public function index() {
        $this->load->view('welcome_message');
    }

    //获取背景图片
    public function getPhoto() {
        $result = $this->Photo_model->getPhotots(20, 6);
        $imgCount = count($result);
        $i = rand(0, $imgCount -1);
        $item = $result[$i];
        echo json_encode(array(
            'img'=> base_url('photos/weather_app/'.$item['name']),
            'count'=>$imgCount
        ));
    }

    //获取天气图片
    public function getCovers() {
        $result = $this->Photo_model->getPhotots(null, 7);
        $imgCount = count($result);
        $i = rand(2, $imgCount - 1);
        $arr = array();
        if ($imgCount > 5) {
            $img1 = base_url('photos/weather_cover/'.$result[$i]['name']);
            $img2 = base_url('photos/weather_cover/'.$result[$i - 1]['name']);
            $img3 = base_url('photos/weather_cover/'.$result[$i - 2]['name']);
            array_push($arr, $img1, $img2, $img3);
        } else {
            for ($j = 0; $j < count($result); $j++) {
                $img = base_url('photos/weather_cover/'.$result[$j]['name']);
                array_push($arr, $img);
            }
        }
        echo json_encode(array(
            'imgs'=> $arr,
            'count'=>count($arr)
        ));
    }

    //获取文章
    public function getArticles() {
        $this->Photo_model->getPhotots(null, 6);
    }

    //获取图片文件夹

    //获取用户信息

    //登录

    //注册

    //找回密码

    //发送短信

    //文章分类

    //发布文章

    //保存草稿

    //删除文章

    //修改文章

    //
}